package wre;

import java.util.*;

public class WordForm {
	private String word;
	private Map<Integer, Integer> retortFreq = new HashMap<Integer, Integer>();

	/**
	 * Basic constructor for WordForm takes in two inputs
	 * 
	 * @param word
	 * @param key
	 */
	public WordForm(String word, Integer key) {
		this.word = word;
		retortFreq.put(key, new Integer(1));
	}

	/**
	 * Returns the word
	 * 
	 * @return
	 */
	public String getWord() {
		return word;
	}

	/**
	 * This method will check and see if the retort is already part of the Map,
	 * if it is not a new instance will be created. If the retort is already in
	 * the Map then the frequency will be incremented
	 * 
	 * @param retort
	 * @return
	 */
	public void insert(String retort) {
		Integer key = new Integer(retort.hashCode());
		if (retortFreq.containsKey(key)) {
			// Inc Freq
			Integer temp = retortFreq.get(key);
			temp++;
			retortFreq.put(key, temp);
		} else {
			// Add Retort ID with Frequency of one
			retortFreq.put(key, new Integer(1));
		}
	}

	/**
	 * This returns the key to the retort that has the highest frequency for
	 * this particular word
	 * 
	 * @return
	 */
	public Integer getHighestFrequency() {
		// Returns the key with the highest frequency
		Integer keyToReturn = new Integer(-1);
		Set<Integer> allKeys = retortFreq.keySet();
		Iterator<Integer> keyIter = allKeys.iterator();
		while (keyIter.hasNext()) {
			Integer curr = keyIter.next();
			if (curr.intValue() > keyToReturn.intValue()) {
				keyToReturn = curr;
			} else if (curr.intValue() == keyToReturn.intValue()) {
				// What to do if equal?
			}
		}
		return keyToReturn;
	}

	public Map<Integer, Integer> getMap() {
		return this.retortFreq;
	}
}